package com.gaoyi.crm.fragment.mtc;

import android.os.Bundle;
import android.widget.RadioGroup;

import androidx.activity.result.ActivityResult;

import com.gaoyi.crm.R;
import com.gaoyi.crm.constant.BundleKeyName;
import com.gaoyi.crm.databinding.FragmentMtcSyncBinding;
import com.gaoyi.crm.db.bean.ResultBean;
import com.gaoyi.crm.db.dto.PmnDto;
import com.gaoyi.crm.db.entity.PmnWithList;
import com.gaoyi.crm.db.query.BaseQuery;
import com.gaoyi.crm.fragment.base.BaseParentFragment;
import com.gaoyi.crm.vm.MtcNoSyncListViewModel;

import java.util.Map;

public class MtcSyncFragment extends BaseParentFragment<FragmentMtcSyncBinding, MtcNoSyncListViewModel, PmnWithList> {

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mtc_sync;
    }

    @Override
    protected int getFragmentId() {
        return R.id.mobile_fragment;
    }

    @Override
    protected void initView() {
        mBinding.rgType.setOnCheckedChangeListener(new MyOnCheckChangeListener());
        mBinding.rgType.check(R.id.rbNoSync);
    }

    private void jumpToResult(ResultBean result) {
        if (result == null) {
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putParcelable(BundleKeyName.RESULT, result);
        mController.navigate(R.id.action_mtcSyncFragment_to_resultFragment, bundle);
        mViewModel.setResult(null);
    }

    @Override
    protected void initFragment() {
        setFragment(new MtcNoSyncListFragment());
        setFragment(new MtcSyncedListFragment());
    }

    @Override
    protected void initLiveData() {
        mViewModel.getResult().observe(getViewLifecycleOwner(), this::jumpToResult);
    }

    private class MyOnCheckChangeListener implements RadioGroup.OnCheckedChangeListener {

        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {
            if (i == R.id.rbNoSync) {
                showFragment(0);
            } else {
                showFragment(1);
            }
        }
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void onRequestPermissionsResult(Map<String, Boolean> result) {

    }

    @Override
    protected void onActivityResult(int requestCode, ActivityResult result) {

    }
}